package com.jindianjichi.subject.common.entity;

import com.jindianjichi.subject.common.enums.ResultCodeEnum;
import lombok.Data;

//@Data
public class Result<T> {
    private Integer code;
    private String message;
    private Boolean success;
    private T data;
public static <T> Result ok(T data){
    Result result = new Result();
    result.setSuccess(true);
    result.setData(data);
    result.setCode(ResultCodeEnum.SUCCESS.getCode());
    result.setMessage(ResultCodeEnum.SUCCESS.getDesc());
    return  result;
}
    public static <T> Result fail(){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        return  result;
    }

    public static <T> Result fail(T data){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(ResultCodeEnum.FAIL.getCode());
        result.setMessage(ResultCodeEnum.FAIL.getDesc());
        result.setData(data);
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Result(Integer code, String message, Boolean success, T data) {
        this.code = code;
        this.message = message;
        this.success = success;
        this.data = data;
    }

    public Result() {
    }
}
